package com.lihongman.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.lihongman.entity.Company;
import com.lihongman.util.DBHelp;
import com.lihongman.util.RowMapper;

public class CompanyDao {

	
	private DBHelp<Company> db = new DBHelp<Company>();

	public  Company findByName(String danwei) {
		String sql = "select company_id,company from t_company where company=?";
		return db.executeQueryForObject(sql, new CompanyRowMapper(), danwei);
	}

	public void save(Company company) {
		String sql = "insert into t_company(company_id,company) value(?,?)";
		db.executeSQL(sql, company.getId(),company.getCompany());
		
	}
	private class CompanyRowMapper implements RowMapper<Company> {
		
		public Company mapperRow(ResultSet rs) throws SQLException {
			Company company = new Company();
			company.setId(rs.getString("company_id"));
			company.setCompany(rs.getString("company"));
			return company;
		}
	}
	
}
